/* eslint-disable no-undef */

import test from './test'

const storage = {
  set (key, value = '') {
    if (!key) return ''
    if (test.object(value)) value = JSON.stringify(value)
    uni.setStorageSync(key, value)
  },
  get (key) {
    if (!key) return ''
    let value = uni.getStorageSync(key)
    try { value = JSON.parse(value) } catch (e) {}
    return value
  },
  remove (key) {
    if (!key) return ''
    uni.removeStorageSync(key)
  },
  clear () {
    uni.clearStorage()
  }
}
export default storage
